<div class="row toolbar">
  <div class="col-md-6">
    <span class="toolbar-header">
      <%= @supplier.new_record? ? "#{t(:new_supplier)}" : "#{t(:edit)} #{t(:supplier)}" %> 
    </span>
  </div>
  <div class="col-md-6 text-right">
    <ul class="toolbar-nav">
      <li><%= link_to simple_icon("user"), @supplier %></li>
      <% if params.has_key?(:drug_id) %>
      	<li><%= link_to simple_icon("user"), drug_path(:id => params[:drug_id]) %></li>
      <% end %>
    </ul>
  </div>
</div>

<% if action_name == "new" and params.has_key?(:drug_id) %>
<p> Use this form to select from existing Suppliers list</p>
	<%= form_for(@supplier, url:drug_suppliers_path) do |fr| %>
		<% if @supplier.errors.any? %>
			<div id="error_explanation">
			  <h2><%= pluralize(@supplier.errors.count, "error") %> prohibited this supplier from being saved:</h2>
			  <ul>
				  <% @supplier.errors.full_messages.each do |message| %>
					<li><%= message %></li>
				  <% end %>
			  </ul>
			</div>
		<% end %>
			
		<div class="form-group">
			<strong>Supplier</strong><br>
			<%= fr.collection_select(:id, Supplier.all, :id, :name, prompt: true) %>
		</div>
		<%= hidden_field_tag :exist, "true" %>
		<%= fr.submit class: "btn btn-primary", action: "create" %>
	<% end %>

<p> Or you can use form below to add new supplier into the list</p>
<% end %>


<%= form_for(@supplier, url:
	if params.has_key?(:drug_id)
		if action_name == "edit" or action_name == "update"
			drug_supplier_path
		else
			drug_suppliers_path
		end
	else
		@supplier
	end
	) do |f| %>
  <% if @supplier.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@supplier.errors.count, "error") %> prohibited this supplier from being saved:</h2>

      <ul>
      <% @supplier.errors.full_messages.each do |message| %>
        <li><%= message %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="form-group">
    <%= f.label :name %><br>
    <%= f.text_field :name %>
  </div>
  <div class="form-group">
    <%= f.label :code %><br>
    <%= f.text_field :code %>
  </div>
  <div class="form-group">
    <%= f.label :website %><br>
    <%= f.text_field :website %>
  </div>
  <div class="form-group">
    <%= f.label :address %><br>
    <%= f.text_area :address %>
  </div>
  <div class="form-group">
    <%= f.label :email %><br>
    <%= f.text_field :email %>
  </div>
  <div class="form-group">
    <%= f.label :phone %><br>
    <%= f.text_field :phone %>
  </div>
  <div class="form-group">
    <%= f.label :fax %><br>
    <%= f.text_field :fax %>
  </div>
  <%= f.submit class: "btn btn-primary" %>  
<% end %>
